package config

import (
	"encoding/json"
	"io/ioutil"
	"log"
	"os"
	"path"
)

var (
	_auth map[string]Third
)

type Third struct {
	Host     string `json:"host"`
	Port     string `json:"port"`
	Pass     string `json:"pass"`
	From     string `json:"from"`
	Nickname string `json:"nickname"`
}

func init() {
	_file, _ := os.Getwd()
	_str, _err := ioutil.ReadFile(path.Join(_file, "auth.json"))
	if nil != _err {
		log.Fatal(_err)
	}

	if _err := json.Unmarshal(_str, &_auth); nil != _err {
		log.Fatal(_err)
	}

	log.Println("loadAuth")
}

func GetAuth(key *string) (*Third, bool) {
	_orz, _ok := _auth[*key]
	return &_orz, _ok
}
